{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'refresh_token': '25.c99e6ef0304f1ce513ba1c99af0f0b1a.315360000.1910326254.282335-21434380', 'expires_in': 2592000, 'session_key': '9mzdCPxsHM7kSmOkDN9OBpzLuis2SzetBKg1ObmSyZAInYSwd1WrYhSyVTD/jgr4/4GxRQKAOU2bVlcZK0vw5igkgq5DfA==', 'access_token': '24.38fdf5ddd41690567c7cf74a096aef55.2592000.1597558254.282335-21434380', 'scope': 'public vis-classify_dishes vis-classify_car brain_all_scope vis-classify_animal vis-classify_plant brain_object_detect brain_realtime_logo brain_dish_detect brain_car_detect brain_animal_classify brain_plant_classify brain_ingredient brain_advanced_general_classify brain_custom_dish brain_poi_recognize brain_vehicle_detect brain_redwine brain_currency brain_vehicle_damage wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理', 'session_secret': '7321418b2a44d4f53ace0ccf38b5e5b8'}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "import requests \n",
    "\n",
    "# client_id 为官网获取的AK， client_secret 为官网获取的SK\n",
    "host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=g3DoqoYf0X3fCIszyhVRPyIl&client_secret=kucSMI5luTntD7z8GsicsQkRu3r3ozXm'\n",
    "response = requests.get(host)\n",
    "if response:\n",
    "    print(response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'log_id': 658999364728434289, 'result_num': 5, 'result': [{'score': 0.6512948274612427, 'name': '草莓'}, {'score': 0.2098165899515152, 'name': '非果蔬食材'}, {'score': 0.06829023361206055, 'name': '车厘子'}, {'score': 0.011962874792516232, 'name': '长丰草莓'}, {'score': 0.006695877760648727, 'name': '樱桃'}]}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "细粒度图像识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/image-classify/v1/classify/ingredient\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('final1.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\"image\":img}\n",
    "access_token = '24.337d5ae322313969a49585663c4cc1eb.2592000.1597556532.282335-21434380'\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'log_id': 4741100842883592209, 'result_num': 5, 'result': [{'score': 0.843688, 'root': '植物-蔷薇科', 'keyword': '草莓'}, {'score': 0.660758, 'root': '植物-其它', 'keyword': '红色草莓'}, {'score': 0.389976, 'root': '商品-水果', 'keyword': '草莓图片'}, {'score': 0.21341, 'root': '商品-水果', 'keyword': '新鲜水果'}, {'score': 0.027375, 'root': '植物-蔷薇科', 'keyword': '樱桃'}]}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "通用物体和场景识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/image-classify/v2/advanced_general\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('final1.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\"image\":img}\n",
    "access_token = '24.337d5ae322313969a49585663c4cc1eb.2592000.1597556532.282335-21434380'\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'log_id': 15949677173120662, 'error_msg': 'service not support', 'error_code': 216102}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "'''\n",
    "图像识别组合API\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/api/v1/solution/direct/imagerecognition/combination\"\n",
    "\n",
    "\n",
    "params = \"{\\\"imgUrl\\\":\\\"https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2560317030,2580393313&fm=26&gp=0.jpg\\\",\\\"scenes\\\":[\\\"animal\\\",\\\"plant\\\",\\\"ingredient\\\",\\\"dishes\\\", \\\"red_wine\\\",\\\"currency\\\",\\\"landmark\\\"]}\"\n",
    "access_token = '24.38fdf5ddd41690567c7cf74a096aef55.2592000.1597558254.282335-21434380'\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/json'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'log_id': 6290045829074164753, 'result': {'classifyByColor': '红葡萄酒/Red Wine', 'subRegionCn': '', 'wineNameCn': '摩标菲凡1901赤霞珠黑姑娘红葡萄酒', 'subRegionEn': '', 'regionEn': '', 'color': '宝石红色/Ruby', 'wineNameEn': 'Wine Standard Collection 1901 Cabernet Sauvignon Feteasca Neagra', 'hasdetail': 1, 'wineryCn': '摩标', 'classifyBySugar': '干型/Dry', 'tasteTemperature': '14-18℃', 'regionCn': '', 'wineryEn': 'Wine Standard', 'grapeCn': '', 'grapeEn': '', 'countryCn': '摩尔多瓦', 'countryEn': 'Moldova', 'description': '此酒呈宝石红色，具有蓝莓、甘草、黑樱桃和黑巧克力芳香四溢，口感丰富，回味柔和愉悦。'}}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "细粒度图像识别—红酒识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/image-classify/v1/redwine\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('final2.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\"image\":img}\n",
    "access_token = '24.38fdf5ddd41690567c7cf74a096aef55.2592000.1597558254.282335-21434380'\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "if response:\n",
    "    print (response.json())\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'refresh_token': '25.ea110f17120969fea50160af3d4182e5.315360000.1910326496.282335-19983354', 'expires_in': 2592000, 'session_key': '9mzdCrExQsoRbCOlqH+2QgMoA6sOzlVSavmdp1DkWGMhINbRllD2PzRJ1six1Me4RaKFL0c2VBtOZc5rYQ+Me+JZm5MXgA==', 'access_token': '24.15eff0f2b104378730d45437745ea641.2592000.1597558496.282335-19983354', 'scope': 'public vis-ocr_ocr brain_ocr_scope brain_ocr_general brain_ocr_general_basic vis-ocr_business_license brain_ocr_webimage brain_all_scope brain_ocr_idcard brain_ocr_driving_license brain_ocr_vehicle_license vis-ocr_plate_number brain_solution brain_ocr_plate_number brain_ocr_accurate brain_ocr_accurate_basic brain_ocr_receipt brain_ocr_business_license brain_solution_iocr brain_qrcode brain_ocr_handwriting brain_ocr_passport brain_ocr_vat_invoice brain_numbers brain_ocr_business_card brain_ocr_train_ticket brain_ocr_taxi_receipt vis-ocr_household_register vis-ocr_vis-classify_birth_certificate vis-ocr_台湾通行证 vis-ocr_港澳通行证 vis-ocr_机动车购车发票识别 vis-ocr_机动车检验合格证识别 vis-ocr_车辆vin码识别 vis-ocr_定额发票识别 vis-ocr_保单识别 vis-ocr_行程单识别 brain_ocr_vin brain_ocr_quota_invoice brain_ocr_birth_certificate brain_ocr_household_register brain_ocr_HK_Macau_pass brain_ocr_taiwan_pass brain_ocr_vehicle_invoice brain_ocr_vehicle_certificate brain_ocr_air_ticket brain_ocr_insurance_doc brain_formula wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理', 'session_secret': '05728b2a6f5579926c2a8bdf9813a18f'}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8许可证识别\n",
    "import requests \n",
    "\n",
    "# client_id 为官网获取的AK， client_secret 为官网获取的SK\n",
    "host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=KCaC246vELlWLg4QaRgT9sy3&client_secret=XYC3U9tEDwtRBkZIRDO4BQqWYMOYkkcG'\n",
    "response = requests.get(host)\n",
    "if response:\n",
    "    print(response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'log_id': 8498883121824273809, 'words_result_num': 11, 'words_result': {'注册资本': {'location': {'width': 0, 'top': 0, 'height': 0, 'left': 0}, 'words': '无'}, '社会信用代码': {'location': {'width': 0, 'top': 0, 'height': 0, 'left': 0}, 'words': '无'}, '单位名称': {'location': {'width': 218, 'top': 369, 'height': 19, 'left': 184}, 'words': '杭州首鸿金融信息服务有限公司'}, '法人': {'location': {'width': 47, 'top': 450, 'height': 18, 'left': 184}, 'words': '符红敏'}, '证件编号': {'location': {'width': 194, 'top': 328, 'height': 14, 'left': 346}, 'words': '330106000404026(1/1)'}, '组成形式': {'location': {'width': 0, 'top': 0, 'height': 0, 'left': 0}, 'words': '无'}, '成立日期': {'location': {'width': 128, 'top': 505, 'height': 17, 'left': 183}, 'words': '2015年04月30日'}, '地址': {'location': {'width': 329, 'top': 423, 'height': 19, 'left': 186}, 'words': '杭州市西湖区古墩路707号城市发展大厦1101室'}, '经营范围': {'location': {'width': 568, 'top': 534, 'height': 336, 'left': 21}, 'words': '接受金融机构委托从事金融信息技术外包接受日构委托从事金融业务流程外包接受金融机构委托从事金融知金流程外包以服务外包方式从事票据中介服务(不含承兑等银行核心业务)投资管理、实业投资、商务信息咨询(除中介)(依须经批准的项目经相关部门准后方可开展经营活动)登记机关★月企业应当于每年1月1日至6月30日通过浙江省企业信用信息公示系统报送上一年度年度报告企业信用信息公示系统网址中华人民共和国国家工商行政管理总局监制'}, '类型': {'location': {'width': 90, 'top': 396, 'height': 19, 'left': 186}, 'words': '有限责任公司'}, '有效期': {'location': {'width': 0, 'top': 0, 'height': 0, 'left': 0}, 'words': '无'}}}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "营业执照识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/ocr/v1/business_license\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('final3.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\"image\":img}\n",
    "access_token = '24.15eff0f2b104378730d45437745ea641.2592000.1597558496.282335-19983354'\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
